package com.itheima.task;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

public class PricticeStream01 {
    /*
    * 定义一个泛型为String类型的List集合，统计该集合中每个字符（注意，不是字符串）出现的次数。
       例如：集合中有”abc”、”bcd”两个元素，程序最终输出结果为：“a = 1,b = 2,c = 2,d = 1”。
    * */
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>(List.of("abc","bcd","redfd","fddvc"));
        StringBuilder stringBuilder = new StringBuilder();
        StringBuilder append = null;
        for (int i = 0; i <list.size() ; i++) {
            String s = list.get(i);
             append = stringBuilder.append(s);
        }
        String s = append.toString();
        char[] chars = s.toCharArray();
        HashMap<Character,Integer> mp = new HashMap<>();
        for (Character ch:chars) {
            mp.put(ch,mp.containsKey(ch)?mp.get(ch)+1:1);
        }
        Set<Character> characters = mp.keySet();
        for (Character shs :characters){
            System.out.println(shs+"="+mp.get(shs));
        }
    }
}
